package com.xiao.hao.config;

import cn.hutool.core.util.ObjectUtil;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeConfig {


    public static String dateFormate(LocalDateTime localDateTime) {

        if (localDateTime == null) {
            return "";
        }

        return DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(localDateTime);
    }

    public static LocalDateTime stringformatDate(String strLocalDateTime) {

        if (ObjectUtil.isEmpty(strLocalDateTime)) {
            return null;
        }
        DateTimeFormatter dateFormatter = strLocalDateTime.indexOf("T") == -1 ?
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") :
                DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        return LocalDateTime.parse(strLocalDateTime, dateFormatter);
    }


    public static String dateFormate() {
        return DateTimeFormatter.ofPattern("/yyyy/MM/dd/").format(LocalDateTime.now());
    }

    public static String getDateFormate() {
        return DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now());
    }

}
